![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
ping-monitor
Advanced tools
An uptime event emitter for http and tcp servers.
npm install ping-monitor
const Monitor = require('ping-monitor');
const myWebsite = new Monitor(options);
myWebsite.on(event, function(response, state) {
// Do something with the response
});
stop
- stop an active monitorrestart
- stop and start an active monitoraddress
- Server address to be monitoredwebsite
- Website address to be monitoredport
- Server port (optional).interval
(defaults to 15 mins) - time interval for polling requests.httpOptions
- allows you to define your http/s request with more control. A full list of the options can be found here: https://nodejs.org/api/http.html#http_http_request_url_options_callback
expect
- allows you define what kind of a response you expect for your endpoint. At the moment expect accepts 1 prop (more to be added in future versions), statusCode
a http status code.
config
{ intervalUnits } - configuration for your Monitor, currently supports one property, intervalUnits
. intervalUnits
specifies which to time unit you want your Monitor to use. There are 4 options, milliseconds
, seconds
, minutes
(default), and hours
.
ignoreSSL
- ignore broken/expired certificatesexpect {
statusCode: Integer, // http status codes
contentSearch: String
}
// http Get
const myApi = new Monitor({
website: 'http://api.ragingflame.co.za',
title: 'Raging Flame',
interval: 5,
config: {
intervalUnits: 'minutes' // seconds, milliseconds, minutes {default}, hours
},
httpOptions: {
path: '/users',
method: 'get',
query: {
id: 3
}
},
expect: {
statusCode: 200
}
});
// http Post
const myApi = new Monitor({
website: 'http://api.ragingflame.co.za',
title: 'Raging Flame',
interval: 10,
config: {
intervalUnits: 'minutes' // seconds, milliseconds, minutes {default}, hours
},
httpOptions: {
path: '/users',
method: 'post',
query: {
first_name: 'Que',
last_name: 'Fire'
},
body: 'Hello World!'
},
expect: {
statusCode: 200
}
});
up
- All is good website is up.down
- Not good, website is down.stop
- Fired when the monitor has stopped.error
- Fired when there's an errortimeout
- Fired when the http request times outobject.website
- website being monitored.object.address
- server address being monitored.object.port
- server port.object.time
- (aka responseTime) request response time.object.responseMessage
- http response code message.object.responseTime
- response time in milliseconds.object.httpResponse
- native http/s response object.object.id
null
- monitor id, useful when persistence.object.title
null
- monitor label for humans.object.isUp
true
- flag to indicate if monitored server is up or down.object.created_at
<Date.now()> - monitor creation date.object.isUp
true
- current uptime status of the monitor.object.port
null
- server port.object.totalRequests
0
- total requests made.object.totalDownTimes
0
- total number of downtimes.object.lastDownTime
<Date.now()> - time of last downtime.object.lastRequest
<Date.now()> - time of last request.object.interval
5
- polling interval in minutesobject.website
null
- website being monitored.object.address
null
- server address being monitored.object.port
null
- server port.'use strict';
const Monitor = require('ping-monitor');
const myMonitor = new Monitor({
website: 'http://www.ragingflame.co.za',
title: 'Raging Flame',
interval: 10 // minutes
});
myMonitor.on('up', function (res, state) {
console.log('Yay!! ' + res.website + ' is up.');
});
myMonitor.on('down', function (res) {
console.log('Oh Snap!! ' + res.website + ' is down! ' + res.statusMessage);
});
myMonitor.on('stop', function (website) {
console.log(website + ' monitor has stopped.');
});
myMonitor.on('error', function (error) {
console.log(error);
});
'use strict';
const Monitor = require('ping-monitor');
const myMonitor = new Monitor({
address: '162.13.124.139',
port: 8080,
interval: 5 // minutes
});
myMonitor.on('up', function (res, state) {
console.log('Yay!! ' + res.address + ':' + res.port + ' is up.');
});
myMonitor.on('down', function (res, state) {
console.log('Oh Snap!! ' + res.address + ':' + res.port + ' is down! ');
});
myMonitor.on('stop', function (res, state) {
console.log(res.address + ' monitor has stopped.');
});
myMonitor.on('error', function (error, res) {
console.log(error);
});
myMonitor.on('timeout', function (error, res) {
console.log(error);
});
Changes
let ping = new Monitor({
website: 'https://google.com',
interval: 5,
config: {
intervalUnits: 'minutes',
generateId: false // defaults is true
}
});
ping.on('up', function (res, state) {
//state.id === null
console.log('Yay!! Google is up');
});
ping.on('error', function (error, res) {
console.error(error);
});
Changes
active
from props (redundant)host
from props (not used)ignoreSSL
to support websites with expired certificates let ping = new Monitor({
website: 'https://wrong.host.badssl.com',
interval: 1,
config: {
intervalUnits: 'minutes' // seconds, milliseconds, minutes {default}, hours
},
ignoreSSL: true
});
ping.on('up', function (res, state) {
console.log('Yay!! Service is up');
});
ping.on('error', function (error, res) {
console.error(error);
});
Changes
let ping = new Monitor({
website: 'https://webservice.com',
interval: 1,
config: {
intervalUnits: 'minutes' // seconds, milliseconds, minutes {default}, hours
}
});
ping.on('up', function (res, state) {
console.log('Yay!! Service is up');
});
ping.on('error', function (error, res) {
console.error(error);
});
Changes
let ping = new Monitor({
website: 'https://ecommorce-shop.com/playstation5',
interval: 0.1,
expect: {
contentSearch: 'In stock'
}
});
ping.on('up', function (res, state) {
console.log('Yay!! Content cantains the phrase "In stock"');
});
ping.on('error', function (error, res) {
console.error(error);
});
Changes
timeout
event to Monitor instance. This event is passed from the htt/s module. myMonitor.on('timeout', function (error, res) {
console.log(error);
});
// also make sure that you are handling the error event
myMonitor.on('error', function (error, res) {
console.log(error);
});
Please note: When the timeout
event is fired, it is followed by the error
event which is created when we manually abort the http request.
Dependencies update
Changes
Monitor
response objectYou can now include a body in your httpOptions
:
// http Post
const myApi = new Monitor({
website: 'http://api.ragingflame.co.za',
title: 'Raging Flame',
interval: 10 // minutes
// new options
httpOptions: {
path: '/users',
method: 'post',
query: {
first_name: 'Que',
last_name: 'Fire'
},
body: 'Hello World!'
},
expect: {
statusCode: 200
}
});
myApi.on('up', function (res, state) {
/*
response {
responseTime <Integer> milliseconds
responseMessage <String> response code message
website <String> url being monitored.
address <String> server address being monitored
port <Integer>
httpResponse <Object> native http/s response object
}
state {
created_at <Date.now()>
isUp <Boolean>
port: <Integer>
totalRequests <Integer>
lastDownTime <Date.now()>
lastRequest <Date.now()>
interval <Integer>
}
*/
});
Changes
Added some utility methods used when updating a monitor and added immediate ping on monitor creation.
pause
method to Monitor.unpause
method to Monitor.Tip: See options section to learn how they work.
Changes
Changes in v0.4.1 give you more control to define your http requests and what response to expect.
httpOptions
prop to Monitor instance options.expect
prop for naming your your monitor.Tip: See options section to learn how they work.
Changes
Most of the changes introduced in this version were introduced to support database persistence.
id
prop, useful when you add database persistence.title
prop for naming your your monitor.active
prop to flag if monitoring is active.totalDownTimes
prop for keeping record of total downtimes.isUp
prop to indicate if monitored server is up or down.website
, address
, totalDownTimes
, active
, active
props to the emitted state
objectstop
event now takes a callback that accepts 2 arguments, response
&& state
(same as the up
and down
events).New Feature
Added a state
object in the response that returns useful monitoring data
State
object
const Monitor = require('ping-monitor');
const myMonitor = new Monitor(options);
myMonitor.on(event, function(response, state) {
/*
response {...}
state {
created_at <Date.now()>
isUp <Boolean>
port: <Integer>
totalRequests <Integer>
lastDownTime <Date.now()>
lastRequest <Date.now()>
interval <Integer>
}
*/
});
Changes made
response
and state
, please see above examples.error
event - required for handling module usage related errorsresponseTime
to the response objecterror
event - now being handled internallynpm test
(MIT License)
Copyright (c) 2013 - 2018 Qawelesizwe Mlilo qawemlilo@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Website Uptime Event Emitter
The npm package ping-monitor receives a total of 1,992 weekly downloads. As such, ping-monitor popularity was classified as popular.
We found that ping-monitor demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.